package com.lxd.order.service;

import com.lxd.order.feign.clients.UserClient;
import com.lxd.order.mapper.OrderMapper;
import com.lxd.order.pojo.Consume;
import com.lxd.order.pojo.Order;
import com.lxd.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private UserClient userClient;

    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);
        Long userId = order.getUserId();
        User user = userClient.findById(userId);
        order.setUser(user);
        // 4.返回
        return order;
    }
    @Transactional
    public boolean consume(Consume consume) {
        if (consume.getUserId()==null)
            throw new RuntimeException("userId is null");
        orderMapper.findById(101L);
        orderMapper.insertMqLog(consume);
        return true;
    }
}
